<template>
	<view class="content">
		<!-- #ifdef H5 || APP-PLUS -->
		<view class="message-title">
			<commonTitle :title="title"></commonTitle>
		</view>
		<!-- #endif -->
		<view class="tip" v-if="fundType==19">说明：每月22日统一发放上月邀请奖励</view>
		<scroll-view class="list-scroll-content" scroll-y="true" @scrolltolower="loadMore"
		refresher-enabled="true" :refresher-triggered="triggered"
		:refresher-threshold="100" 
		@refresherrefresh="onRefresh" @refresherrestore="onRestore" 
		>
			
			<view class="my-share-detail" v-if="list.length>0">
					<view class="list-item" v-for="(item,index) in list" :key="index">
						<view class="item-left">
							<view class="item-title">{{item.intro}}</view>
							<view class="item-time">{{item.createTime}}</view>
						</view>
						<view class="item-captial-num">{{item.amount}}</view>
					</view>
					
			</view>
			<view class="nodata" v-else>
				<image src="../../../static/common/nodata-sub.png" class="nodataimg"></image>
			</view>
			
			
			
		</scroll-view>
		
		
		
	</view>
</template>

<script>
	const util = require('../../../util/util.js');
	import commonTitle from'../../../components/sub-titile/title.vue'
	export default{
		components:{
			commonTitle
		},
		data () {
			return {
				apptoken:"",
				pageIndex:1,
				nodata:false,
				list:[],
				fundType:"",
				title:"",
				triggered: true,
				freshing:false,
				unFinishedStatus:"",
			}
		},
		onLoad(options) {
			this.fundType = options.fundType;
			this.apptoken = uni.getStorageSync("apptoken");
			if(options.fundType == 19){
				this.title = "奖励金明细";
			}else{
				this.title = "佣金明细";
			}
			this.getList();
		},
		methods: {
			onRefresh() {
					if (this.freshing) return;
					this.freshing = true;
					this.getList(null,"onRefresh");
					
			},
			onRestore() {
					this.triggered = 'restore'; // 需要重置
			},
			getList(type,refsh){
				const _this = this;
				if(refsh){
					this.pageIndex = 1;
				}
				console.log(this.pageIndex)
				if(this.nodata && !refsh){
					//最后一页停止请求
					return;
				}
				uni.request({
					url:this.$API.URL + this.$API.yongjin_list,
					data:{apptoken:this.apptoken,pageIndex:this.pageIndex,fundType:this.fundType},
					success(res) {
						console.log(res);
						if(res.data.success){
							if(res.data.data.length < 1 && _this.pageIndex!=1){
								_this.$CommonJS.showToast("没有更多数据了");
								_this.nodata = true;
								_this.triggered = false;
								_this.freshing = false;
								return;
							}
							if(type){
								//分页
								res.data.data.forEach(item=>{
									_this.list.push(item)
								})
								
							}else{
								_this.list = res.data.data;
							}
							_this.pageIndex ++;
							if(refsh && refsh == "onRefresh"){
								_this.triggered = false;
								_this.freshing = false;
								uni.showToast({
									title:"刷新成功"
								})
							}
						}else{
							_this.triggered = false;
							_this.freshing = false;
							_this.$CommonJS.showToast(res.data.msg);
						}
					}
				})
			},
			//分页加载-防抖
			loadMore: util.throttle(function(e) {
				if(!this.nodata){
					this.getList(1);
				}
			}, 300),
			
		}
		
	}
</script>

<style scoped>
	@import url("sub-reward.css");
</style>
